package cn.itcast.activiti.servlet.processinstance;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.runtime.ProcessInstanceQuery;
import org.apache.catalina.connector.Request;

import com.sun.org.apache.regexp.internal.recompile;

import cn.itcast.activiti.common.ProcessEngineUtils;

/**
 * 根据流程定义的Id查询流程实例
 * @author LEE.SIU.WAH
 * @email lixiaohua7@163.com
 * @date 2016年5月6日 下午2:43:15
 * @version 1.0
 */

@WebServlet("/queryProcessInstanceByPdId.action")
public class QueryProcessInstanceByPdIdServlet extends HttpServlet{
	private static final long serialVersionUID = 1209729424878402317L;
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		String pdId=request.getParameter("pdId");
		System.out.println(pdId);
		/** 获取流程引擎 */
		ProcessEngine pe=ProcessEngineUtils.getProcessEngine();
		/** 获取运行时服务 */
		RuntimeService rs=pe.getRuntimeService();
		/** 创建流程实例查询对象*/
		ProcessInstanceQuery piq=rs.createProcessInstanceQuery();
		
		List<ProcessInstance> piLists=piq.processDefinitionId(pdId).orderByProcessInstanceId().asc().list();
		
		request.setAttribute("piLists", piLists);
		
		request.getRequestDispatcher("/processInstance.jsp").forward(request, response);
		
		
	}

	
}
